/*
 *  Copyright (C) 2010 Martin Haulrich <mwh.isv@cbs.dk> and Matthias Buch-Kromann <mbk.isv@cbs.dk>
 *
 *  This file is part of the IncrementalParser package.
 *
 *  The IncrementalParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.osdtsystem.incparser.loss;

import org.osdtsystem.incparser.graphs.BaseGraph;
import org.osdtsystem.incparser.graphs.ConllAdapter;
import org.osdtsystem.incparser.graphs.LocalGraph;

/**
 *
 * @author Martin Haulrich
 */
public class LabelledLoss implements Loss {
    public double loss(ConllAdapter gold, ConllAdapter system) {
        BaseGraph goldGraph = gold.baseGraph();
        BaseGraph systemGraph = system.baseGraph();
        double loss = 0;
        for (int node = 1; node < gold.nodes(goldGraph); node++) {
            LocalGraph localGraphGold = gold.localGraph(goldGraph, node);
            LocalGraph localGraphSystem = system.localGraph(systemGraph, node);
            int headGold = localGraphGold.headNode();
            int headSystem = localGraphSystem.headNode();
            int labelGold = localGraphGold.headType();
            int labelSystem = localGraphSystem.headType();

            // TODO: Martin's original code:
            if (headGold != headSystem || labelGold != labelSystem)
                loss++;

            // TODO: Alternative loss function:
            //if (headGold != headSystem)
            //    loss++;
            //if (labelGold != labelSystem)
            //    loss++;
        }
        return loss;
    }
}
